package cnbdqn.mail;

import java.util.Properties;

import javax.mail.Address;
import javax.mail.Message.RecipientType;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import org.junit.Test;

public class QuartzMail {
	@Test
	public void hehe() {
		System.out.println(111);
		Properties properties = new Properties();
		properties.put("mail.smtp.host", "smtp.exmail.qq.com");
		properties.put("mail.smtp.port", "587");
		properties.put("mail.smtp.ssl.enable", "true");
		properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLServerSocketFactory");
		properties.put("mail.smtp.auth", "true");
		Session session = Session.getDefaultInstance(properties);
		session.setDebug(true);
		MimeMessage message = new MimeMessage(session);
		Transport transport = null;
		try {
			Address fromAddress = new InternetAddress("1639145898@qq.com");
			message.setFrom(fromAddress);
			Address address = new InternetAddress("2653944718@qq.com");
			message.setRecipient(RecipientType.TO, address);
			message.setSubject("标题");
			message.setText("hello world");
			message.saveChanges();
			transport = session.getTransport("smtp");
			transport.connect("smtp.qq.com", "1639145898@qq.com", "qihsuitqluancdbg");
			transport.sendMessage(message, message.getAllRecipients());
			System.out.println("发送成功");
			transport.close();
		} catch (AddressException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchProviderException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MessagingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
